#!/bin/bash

echo "=========================================="
echo "Flask大数据可视化项目 - 自动安装脚本"
echo "=========================================="
echo

echo "检查Python环境..."
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3环境，请先安装Python 3.7+"
    exit 1
fi

python3 --version

echo
echo "创建虚拟环境..."
python3 -m venv venv
if [ $? -ne 0 ]; then
    echo "错误: 创建虚拟环境失败"
    exit 1
fi

echo
echo "激活虚拟环境..."
source venv/bin/activate

echo
echo "升级pip..."
python -m pip install --upgrade pip

echo
echo "安装项目依赖..."
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
if [ $? -ne 0 ]; then
    echo "错误: 安装依赖失败"
    exit 1
fi

echo
echo "=========================================="
echo "安装完成！"
echo "=========================================="
echo
echo "使用方法:"
echo "1. 运行 ./start_app.sh 启动应用"
echo "2. 或者运行 ./activate_venv.sh 激活环境后手动运行 python app.py"
echo
echo "应用将在 http://127.0.0.1:5000 启动"
echo
